home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / perl40_2.zip / HANDY.H < prev    next >
C/C++ Source or Header  |  1991-11-28  |  4KB  |  147 lines

  1. /* $RCSfile: handy.h,v $$Revision: 4.0.1.3 $$Date: 91/11/05 22:54:26 $
  2.  *
  3.  *    Copyright (c) 1991, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * $Log:    handy.h,v $
  9.  * Revision 4.0.1.3  91/11/05  22:54:26  lwall
  10.  * patch11: erratum
  11.  *
  12.  * Revision 4.0.1.2  91/11/05  17:23:38  lwall
  13.  * patch11: prepared for ctype implementations that don't define isascii()
  14.  *
  15.  * Revision 4.0.1.1  91/06/07  11:09:56  lwall
  16.  * patch4: new copyright notice
  17.  *
  18.  * Revision 4.0  91/03/20  01:22:15  lwall
  19.  * 4.0 baseline.
  20.  *
  21.  */
  22.  
  23.  
  24. #ifdef NULL
  25. #undef NULL
  26. #endif
  27. #ifndef I286
  28. #  define NULL 0
  29. #else
  30. #  define NULL 0L
  31. #endif
  32. #define Null(type) ((type)NULL)
  33. #define Nullch Null(char*)
  34. #define Nullfp Null(FILE*)
  35.  
  36.  
  37. #ifdef UTS
  38. #define bool int
  39. #else
  40. #define bool char
  41. #endif
  42.  
  43.  
  44. #ifdef TRUE
  45. #undef TRUE
  46. #endif
  47. #ifdef FALSE
  48. #undef FALSE
  49. #endif
  50. #define TRUE (1)
  51. #define FALSE (0)
  52.  
  53.  
  54. #define Ctl(ch) (ch & 037)
  55.  
  56.  
  57. #define strNE(s1,s2) (strcmp(s1,s2))
  58. #define strEQ(s1,s2) (!strcmp(s1,s2))
  59. #define strLT(s1,s2) (strcmp(s1,s2) < 0)
  60. #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
  61. #define strGT(s1,s2) (strcmp(s1,s2) > 0)
  62. #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
  63. #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
  64. #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
  65.  
  66.  
  67. #if defined(CTYPE256) || !defined(isascii)
  68. #define isALNUM(c) (isalpha(c) || isdigit(c) || c == '_')
  69. #define isALPHA(c) isalpha(c)
  70. #define isSPACE(c) isspace(c)
  71. #define isDIGIT(c) isdigit(c)
  72. #define isUPPER(c) isupper(c)
  73. #define isLOWER(c) islower(c)
  74. #else
  75. #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
  76. #define isALPHA(c) (isascii(c) && isalpha(c))
  77. #define isSPACE(c) (isascii(c) && isspace(c))
  78. #define isDIGIT(c) (isascii(c) && isdigit(c))
  79. #define isUPPER(c) (isascii(c) && isupper(c))
  80. #define isLOWER(c) (isascii(c) && islower(c))
  81. #endif
  82.  
  83.  
  84. #define MEM_SIZE unsigned int
  85.  
  86.  
  87. /* Line numbers are unsigned, 16 bits. */
  88. typedef unsigned short line_t;
  89. #ifdef lint
  90. #define NOLINE ((line_t)0)
  91. #else
  92. #define NOLINE ((line_t) 65535)
  93. #endif
  94.  
  95.  
  96. #ifndef lint
  97. #ifndef LEAKTEST
  98. #ifndef safemalloc
  99. char *safemalloc();
  100. char *saferealloc();
  101. void safefree();
  102. #endif
  103. #ifndef MSDOS
  104. #define New(x,v,n,t)  (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  105. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  106. #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
  107.     bzero((char*)(v), (n) * sizeof(t))
  108. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  109. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  110. #else
  111. #define New(x,v,n,t)  (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
  112. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
  113. #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
  114.     bzero((char*)(v), (n) * sizeof(t))
  115. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  116. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  117. #endif /* MSDOS */
  118. #define Safefree(d) safefree((char*)d)
  119. #define Str_new(x,len) str_new(len)
  120. #else /* LEAKTEST */
  121. char *safexmalloc();
  122. char *safexrealloc();
  123. void safexfree();
  124. #define New(x,v,n,t)  (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  125. #define Newc(x,v,n,t,c)  (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  126. #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
  127.     bzero((char*)(v), (n) * sizeof(t))
  128. #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  129. #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  130. #define Safefree(d) safexfree((char*)d)
  131. #define Str_new(x,len) str_new(x,len)
  132. #define MAXXCOUNT 1200
  133. long xcount[MAXXCOUNT];
  134. long lastxcount[MAXXCOUNT];
  135. #endif /* LEAKTEST */
  136. #define Copy(s,d,n,t) (void)bcopy((char*)(s),(char*)(d), (n) * sizeof(t))
  137. #define Zero(d,n,t) (void)bzero((char*)(d), (n) * sizeof(t))
  138. #else /* lint */
  139. #define New(x,v,n,s) (v = Null(s *))
  140. #define Newc(x,v,n,s,c) (v = Null(s *))
  141. #define Newz(x,v,n,s) (v = Null(s *))
  142. #define Renew(v,n,s) (v = Null(s *))
  143. #define Copy(s,d,n,t)
  144. #define Zero(d,n,t)
  145. #define Safefree(d) d = d
  146. #endif /* lint */
  147.